package br.com.LeitorLog.gui;

import java.awt.Color;
import java.io.IOException;
import java.nio.charset.Charset;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.LineBorder;

import br.com.LeitorLog.gui.util.FileUtils;

/**
 * PainelSobre
 *
 * @since 30/01/2013 10:06:58
 */
public class PainelSobre extends JPanel {

	private static final long serialVersionUID = 6881115014694205524L;
	private static JTextArea textArea = new JTextArea();

	/**
	 * Create the panel.
	 */
	public PainelSobre() {
		super();
		initGUI();
		initComponents();
	}
	
	public void initGUI() {
		
		JScrollPane scrollPane = new JScrollPane();
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 450, Short.MAX_VALUE)
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
		);
		scrollPane.setViewportView(textArea);
		// setando a politica de utilizar sempre o vertical scroll
		scrollPane.setVerticalScrollBarPolicy(
                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		
		textArea.setBorder(new LineBorder(new Color(0, 0, 0)));
		
		// setando a quebra de linha quando uma linha for muito grande
		textArea.setLineWrap(true);
		textArea.setWrapStyleWord(true);
		
		textArea.setEditable(false);
		setLayout(groupLayout);
		
	}
	
	private void initComponents() {
		if (System.currentTimeMillis() > 0) {
			try {
				byte[] vBytes = FileUtils.getBytesFromFile("/change.log");
				textArea.setText(new String(vBytes, Charset.forName("UTF-8")));
				textArea.setCaretPosition(0);
			} catch (IOException e) {
				textArea.setText("(erro no arquivo change.log)");
			}
		}
	}
}
